<?php
//Include database connection
include("config.php");

//Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

//Information sent from form
$id=$_POST['id'];
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$repeatpassword=$_POST['repeatpassword'];
$bandbreedte=$_POST['bandbreedte'];
$gebruikers=$_POST['gebruikers'];
$authenticatie=$_POST['authenticatie'];
$domein=$_POST['domein'];
$groepen=$_POST['groepen'];
$administratie=$_POST['administratie'];

//Check if passwords match
if($mypassword != $repeatpassword){
    echo "Passwords do not match. Please type again.";
    exit();
}

//Check if password/repeat password is empty
if(empty($mypassword) || empty($repeatpassword)) die('Type username and password.');

//Encrypt password
$encrypted_mypassword=MD5($mypassword);
$encrypted_repeatpassword=MD5($repeatpassword);

//Protect MySQL injection
$encrypted_mypassword = stripslashes($encrypted_mypassword);
$encrypted_repeatpassword = stripslashes($encrypted_repeatpassword);
$encrypted_mypassword = mysql_real_escape_string($encrypted_mypassword);
$encrypted_repeatpassword = mysql_real_escape_string($encrypted_repeatpassword);
    
$result = mysql_query("UPDATE members SET password='$encrypted_mypassword', bandbreedte='$bandbreedte', gebruikers='$gebruikers', authenticatie='$authenticatie', domein='$domein', groepen='$groepen', administratie='$administratie' WHERE id='$id'")
or die(mysql_error());
header("Location: new_page_1.php");
?>